package com.zjitc.common;

/**
 * Created by lenovo on 2018/4/1.
 */
public class ServerResponse<T> {

    private Integer status;

    private String msg;

    private T data;


    private ServerResponse(Integer status) {
        this.status = status;
    }

    private ServerResponse(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    private ServerResponse(Integer status, T data) {
        this.status = status;
        this.data = data;
    }

    private ServerResponse(Integer status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public boolean success() { return this.status.equals(ServerResponseCode.SUCCESS); }

    public static <T> ServerResponse<T> createBySuccess(){
        return new ServerResponse<>(ServerResponseCode.SUCCESS);
    }

    public static <T> ServerResponse<T> createBySuccessMessage(String msg) {
        return new ServerResponse<>(ServerResponseCode.SUCCESS, msg);
    }

    public static <T> ServerResponse<T> createSuccess(T object) {
        return new ServerResponse<>(ServerResponseCode.SUCCESS, object);
    }

    public static <T> ServerResponse<T> createSuccess(String msg, T object) {
        return new ServerResponse<>(ServerResponseCode.SUCCESS, msg, object);
    }

    public static <T> ServerResponse<T> createError(String msg) {
        return new ServerResponse<>(ServerResponseCode.ERROR, msg);
    }

    public static <T> ServerResponse<T> createError(T object) {
        return new ServerResponse<>(ServerResponseCode.ERROR, object);
    }

    public static <T> ServerResponse<T> createByErrorMessage(String msg, T object) {
        return new ServerResponse<>(ServerResponseCode.ERROR, msg, object);
    }
    public static <T> ServerResponse<T> createByErrorCodeMessage(int errorCode, String errorMessage){
        return new ServerResponse<>(errorCode, errorMessage);
    }
}
